package com.zq.assistant.func.ioc.finder.method;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangqiang on 17-7-11.
 */

public class BaseMethodFinder implements InjectMethodFinder {

    private Class<?> abortClass;

    public BaseMethodFinder(Class<?> abortClass) {
        this.abortClass = abortClass;
    }

    @Override
    public List<Method> findInjectMethod(Class targetClass, Class<? extends Annotation> annotationClass) {

        List<Method> methodList = new ArrayList<>();

        while (!abortClass.equals(targetClass)) {

            Method[] methods = targetClass.getDeclaredMethods();
            for (Method method :
                    methods) {

                if (method.getAnnotation(annotationClass) != null) {
                    methodList.add(method);
                }
            }
            targetClass = targetClass.getSuperclass();
        }
        return methodList;
    }
}
